package com.net.xpay.admin.controller.admin;

import com.net.common.model.ResultData;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.sync.CommonSafePayBatch;
import com.net.xpay.common.manager.sync.CommonSafePayBatchManager;
import com.net.xpay.core.model.SafePayBatchSearchModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/safe-pay-batch")
@Api(tags = "运营/商户打款批次", description = "运营 商户打款批次 net")
public class AdminSafePayBatchController {

    @Autowired
    private CommonSafePayBatchManager commonSafePayBatchManager;

    @ApiOperation("搜索")
    @PostMapping("/search")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'safe-pay-batch::search')")
    public ResultPagedList<CommonSafePayBatch> searchSafePayBatch(@RequestBody SafePayBatchSearchModel searchModel) {
        List<CommonSafePayBatch> records = commonSafePayBatchManager.search(searchModel);
        long count = commonSafePayBatchManager.searchCount(searchModel);

        return new ResultPagedList<>(records, count, searchModel);
    }

    @ApiOperation("搜索单个安全转账批次")
    @GetMapping
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'safe-pay-batch::get')")
    public ResultData<CommonSafePayBatch> getSafePayBatch(Long id) {
        CommonSafePayBatch safePayBatch = commonSafePayBatchManager.getById(id);
        return new ResultData<>(safePayBatch);
    }
}


